﻿using System;
using Wei8808Cms.BLL;
using Wei8808Cms.Model;
using Wei8808Cms.WebSite.UI;

namespace Wei8808Cms.WebSite.admin.Adbanner
{
    public partial class EditAdbannerInfoForm : BasicPage
    {
        public string Id;

        private readonly AdbannerBLL _bll = new AdbannerBLL();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(Request.Params["id"]))
            {
                JscriptMsg(350, 230, "错误提示", "<b>出现错误啦！</b>您要修改的信息不存在或参数不正确。", "back", "Error");
                return;
            }
            Id = Request.Params["id"];
            if (Page.IsPostBack) return;
            chkLoginLevel("editAdbanner");
            ShowInfo(this.Id);
        }

        private void ShowInfo(string id)
        {
            var model = _bll.GetAdbannerInfo(id);
            txtTitle.Text = model.Title;
            txtImgUrl.Text = model.ImgUrl;
            txtLinkUrl.Text = model.LinkUrl;
            txtTopRemark.Text = model.TopRemark;
            txtBottomRemark.Text = model.BottomRemark;
            rblIsLock.SelectedValue = model.IsLock.ToString();
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                var model = new AdbannerInfo
                {
                    Id = Id,
                    Title = txtTitle.Text.Trim(),
                    ImgUrl = txtImgUrl.Text.Trim(),
                    LinkUrl = txtLinkUrl.Text.Trim(),
                    TopRemark = txtTopRemark.Text.Trim(),
                    BottomRemark = txtBottomRemark.Text.Trim(),
                    IsLock = 0
                };
                if (rblIsLock.Items[0].Selected)
                {
                    model.IsLock = 0;
                }
                if (rblIsLock.Items[1].Selected)
                {
                    model.IsLock = 1;
                }
                model.ModifyUser = "李波";
                model.ModifyTime = DateTime.Now;
                if (_bll.Update(model))
                {
                    JscriptPrint("修改成功！", "AdbannerMasterForm.aspx", "Success");
                }
                else
                {
                    JscriptPrint("修改失败！", "AdbannerMasterForm.aspx", "Error");
                }
            }
            catch (Exception ex)
            {
                JscriptPrint("异常：" + ex.Message, "AdbannerMasterForm.aspx", "Error");
            }

        }
    }
}